import {parsePercent, numberHandle} from '~/utils/number';

export const formatTooltip = (params, isROI, num = 2) => {
    let resultName = '';
    const tooltipList = params.map(chartItem => {
        const {seriesType, seriesName, name, value, data: {ROI}, marker} = chartItem;
        let result;
        resultName = name;

        if (seriesType === 'bar') {
            result = `<br/>${marker} ${seriesName}: ${numberHandle(value, 2)}`;
        }
        else if (isROI) {
            result = `<br/>${marker} ${seriesName}: ${parsePercent(value, num)}`;
        }
        else {
            result = `<br/>${marker} ${seriesName}: ${numberHandle(value, 2)}`;
        }

        return result;
    });

    return resultName + tooltipList.join('');
};
